﻿using System;
using System.Linq;
using System.Text;
using System.Web.UI;
using Omu.AwesomeWebForms;

namespace VerySimple
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CategoryAjaxDropdown.Value = "3";
                CategoryAjaxRadioList.Value = "1";
                FruitLookup.Value = "5";
                FruitsMultiLookup.Value = new[] { 1, 2, 3 }.ToJson();
                CategoriesCheckboxList.Value = new[] { 3, 4 }.ToJson();
            }
        }

        protected void Show(object sender, EventArgs e)
        {
            var c1 = Aja.Categories.Single(o => o.Id.ToString() == CategoryAjaxDropdown.Value);
            var c2 = Aja.Categories.SingleOrDefault(o => o.Id.ToString() == CategoryAjaxRadioList.Value) ?? new Category();
            var c3 = Aja.Fruits.SingleOrDefault(o => o.Id.ToString() == FruitLookup.Value) ?? new Fruit();

            var fruits = FruitsMultiLookup.Value.GetIntArray();
            var c4 = Aja.Fruits.Where(o => fruits.Contains(o.Id)).Select(o => o.Name).ToArray();

            var categories = CategoriesCheckboxList.Value.GetIntArray();
            var c5 = Aja.Categories.Where(o => categories.Contains(o.Id)).Select(o => o.Name).ToArray();

            var s = new StringBuilder();
            s.AppendLine("<h2>you selected:</h2>");
            s.AppendLine("<br/>AjaxDropdown Category: " + c1.Name);
            s.AppendLine("<br/>AjaxRadioList Category: " + c2.Name);
            s.AppendLine("<br/>Lookup Fruit: " + c3.Name);
            s.AppendLine("<br/>MultiLookup Fruits: " + string.Join(",", c4));
            s.AppendLine("<br/>AjaxCheckboxList Fruits: " + string.Join(",", c5));
            s.AppendLine("<br/>AjaxList Fruits is at page: " + FruitsAjaxList.PageNumber);

            Result.Text = s.ToString();
        }
    }
}
